/**********************************************************************************************/
/**********************************************************************************************/
/***************Main Code for****************************************************************/
**		"Inalienable Human Capital and Inevitable Corporate Payouts"				  

*About the uploaded data:
*(1) All data sources are clearly demonstrated in the paper.
*(2) The sample data illustrates the format of the actual datasets.
*(3) The GroupID is a randomized number corresponding to the firm identifier.
*    The actual firm identifier is masked in the sample data.		
/**********************************************************************************************/
/**********************************************************************************************/
clear * 

global datadir "~"

cd "$datadir"

global control "llogasset lleverage llogage lmb lgsale lopcfasset2 learn_vol lcheat lroa"
global SampSelect "misstate!=1 & misincorp!=1 & prcc_f>=1 & at>=1 & utf!=1"
global repoption "star(* 0.1 ** 0.05 *** 0.01) b(%12.3f) t(%12.3f) ar2(%12.3f) sfmt(0) nogap compress replace"




	
/**********************************************************************/
/***********************Table 1  -- Summary Stat***********************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

global sumvar " divy_t iddr $control "

sum2docx $sumvar if $SampSelect & (treat==1 | control4==1) & miss==0 using Table1_Summary.docx, replace stats(N mean(%9.3f) sd(%9.3f) p25(%9.3f) median(%9.3f) p75(%9.3f))

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/***********************Table 2  -- Baseline***************************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr if $SampSelect & (treat==1 | control4==1) & miss==0, absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1) & miss==0, absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

esttab using Table2_Baseline.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/***********************Table 3  -- Dynamic***************************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr_l3 iddr_l2 iddr_l1 iddr_0 iddr_f1 iddr_f2 iddr_f3 iddr_f4 if $SampSelect & (treat==1 | control4==1) & miss==0, absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

eststo: quietly reghdfe divy_t $control iddr_l3 iddr_l2 iddr_l1 iddr_0 iddr_f1 iddr_f2 iddr_f3 iddr_f4 if $SampSelect & (treat==1 | control4==1) & miss==0 , absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

esttab using Table3_Dynamic.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/**************Table 4 -- Determinants of IDDR**************************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

bysort ss fyear:egen divy_t_state=mean(divy_t)
duplicates drop state fyear,force
xtset ss fyear

gen l_gdpgrowth=l.gdpgrowth
gen l_log_realgdp=l.log_realgdp
gen l_unemployment=l.unemployment
gen l_logpopulation=l.logpopulation
gen l_political=l.political
gen l_union1=l.union1
gen l_tax=l.tax
gen l_idd=l.idd
gen l_divy_t_state=l.divy_t_state

global cvm="l_idd l_gdpgrowth l_log_realgdp l_logpopulation l_union1 l_tax"

estimates clear
quietly stset fyear, id(ss) failure(iddr==1)

eststo: quietly stcox  l_divy_t_state if l_gdpgrowth!=., vce(cluster ss)
eststo: quietly stcox  l_divy_t_state $cvm , vce(cluster ss)
eststo: quietly stcox  l_divy_t_state $cvm l_political , vce(cluster ss)

esttab using Table4_Determinants.csv, $repoption pr2(%12.3f)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/********************Table 5 -- CroSecKeyTalents******************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr_keyhumancapital iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_skill iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_hightec_ff iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) keepsingletons

esttab using Table5_CroSecKeyTalents.csv, $repoption drop(_cons) order(iddr_keyhumancapital iddr_skill iddr_hightec_ff iddr) 

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/********************Table 6 -- CroSecCorGov******************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr_gindex iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_eindex iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_inst iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) keepsingletons

esttab using Table6_CroSecCorGov.csv, $repoption drop(_cons) order(iddr_gindex iddr_eindex iddr_inst iddr) 

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/********************Table 7 -- CroSecFinCon******************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr_leverage iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_cheat iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_edf iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) keepsingletons

esttab using Table7_CroSecFinCon.csv, $repoption drop(_cons) order(iddr_leverage iddr_cheat iddr_edf iddr) 

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/********************Table 8 -- CroSecProMktComp******************/
/**********************************************************************/
set more off
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr_fluid iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_thhi1 iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr_tnic3tsimm iddr if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) keepsingletons

esttab using Table8_CroSecProMktComp.csv, $repoption drop(_cons) order(iddr_fluid iddr_thhi1 iddr_tnic3tsimm iddr) 

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/










/**********************************************************************/
/***********************Appendix***************************************/
/**********************************************************************/




/**********************************************************************/
/*****************AppxFigA -- Dynamic****************************/
/**********************************************************************/
clear *
use FM_CohortSample.dta,clear

quietly reghdfe divy_t $control iddr_l3 iddr_l2 iddr_l1 iddr_0 iddr_f1 iddr_f2 iddr_f3 iddr_f4 if $SampSelect & (treat==1 | control4==1) , absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

ereturn list
dis e(N)-e(df_m)-e(df_a)
gen t=invttail(43776,0.025)
forvalues i = 1/3{ 
	gen b_before`i'  = _b[iddr_l`i'] 
	gen se_before`i' = _se[iddr_l`i']
	gen LB_before`i' = b_before`i' - t * se_before`i' 
	gen UB_before`i' = b_before`i' + t * se_before`i'
}
gen b_after0  = _b[iddr_0] 
gen se_after0 = _se[iddr_0]
gen LB_after0 = b_after0 - t * se_after0
gen UB_after0 = b_after0 + t * se_after0
forvalues i=1/4 { 
	gen b_after`i'  = _b[iddr_f`i'] 
	gen se_after`i' = _se[iddr_f`i']
	gen LB_after`i' = b_after`i' - t * se_after`i'
	gen UB_after`i' = b_after`i' + t * se_after`i'
}  
gen b = .
gen LB = .
gen UB = .
gen tDID = fyear - iddr_year
forvalues i=1/3{
	replace b  = b_before`i'  if tDID == -`i'
	replace LB = LB_before`i' if tDID == -`i'
	replace UB = UB_before`i' if tDID == -`i'
}
forvalues i=0/4{
	replace b  = b_after`i'    if tDID == `i'
	replace LB = LB_after`i'   if tDID == `i'
	replace UB = UB_after`i'   if tDID == `i'
}
replace b = 0 if tDID==-4
keep tDID b LB UB
duplicates drop tDID,force
keep if inrange(tDID,-4,4)
sort tDID

twoway (connected b tDID, sort)(rcap LB UB tDID), scheme(s1mono) legend(off) xtitle("") yline(0,lpattern(dash)) xline(0,lpattern(dash)) xlabel(-4 "<=-4" -3 "-3" -2 "-2" -1 "-1" 0 "0" 1 "1" 2 "2" 3 "3" 4 ">=4")

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/*****************AppxTabC1 -- PSM****************************/
/**********************************************************************/

**1. PanelA_Baseline
clear *
use FM_NotCohortSample.dta

xi:psmatch2 iddrt $control i.region i.cohort_iddr if fyear>=1994 & misstate!=1 & misincorp!=1 & prcc_f>=1 & at>=1 & utf!=1,outcome(divy_t) n(1) ate ties logit common

gen pair = _id if _treated==0 
replace pair = _n1 if _treated==1 
bysort pair: egen paircount = count(pair) 
gen temp1=1 if (paircount>=2 & paircount<3) 

estimates clear
xi: quietly logit iddrt $control i.region i.cohort_iddr if $SampSelect
	est sto m1
	
xi: quietly logit iddrt $control i.region i.cohort_iddr if $SampSelect & temp1==1
	est sto m2

esttab m* using AppxTabC1_PanelA_Baseline.csv, $repoption pr2(%12.3f) drop(_Iregion_* _Icohort* _cons)

**2. PanelB_PostDiff
pstest $control if temp1==1

**3. PanelC_Dynamic
clear *
use FM_MatchedSample_cohort.dta

estimates clear
eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

eststo: quietly reghdfe divy_t $control iddr_l3 iddr_l2 iddr_l1 iddr_0 iddr_f1 iddr_f2 iddr_f3 iddr_f4 if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

esttab using AppxTabC1_PanelC_Dynamic.csv, $repoption order(iddr iddr_*)  drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/****************AppxTabC2 -- AlterMeasures************************/
/**********************************************************************/
clear *
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_total iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

eststo: quietly reghdfe divceq_t iddr $control if $SampSelect & ceq>0 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

eststo: quietly reghdfe divsale_t iddr $control if $SampSelect & sale>0 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

eststo: quietly reghdfe payout_t iddr $control if $SampSelect & ibc>0 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

eststo: quietly reghdfe divoancf_t iddr $control if $SampSelect & oancf>0 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

esttab using AppxTabC2_AlterMeasures.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/****************AppxTabC3 -- HighFixed************************/
/**********************************************************************/
clear *
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr if $SampSelect & miss==0 & (treat==1 | control4==1), absorb(gv#cohort fyear#cohort regionfyear#cohort sic2fyear#cohort incofyear#cohort) keepsingletons cluster(ss)

eststo: quietly reghdfe divy_t iddr_l3 iddr_l2 iddr_l1 iddr_0 iddr_f1 iddr_f2 iddr_f3 iddr_f4 if $SampSelect & miss==0 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort regionfyear sic2fyear incofyear) keepsingletons cluster(ss)

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort regionfyear sic2fyear incofyear) keepsingletons cluster(ss)

eststo: quietly reghdfe divy_t iddr_l3 iddr_l2 iddr_l1 iddr_0 iddr_f1 iddr_f2 iddr_f3 iddr_f4 $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort regionfyear sic2fyear incofyear) keepsingletons cluster(ss)

esttab using AppxTabC3_HighFixed.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/****************AppxTabC4 -- AddRobust************************/
/**********************************************************************/
clear *
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr $control if $SampSelect & state!="CA" & state!="MA" & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & incorp!="DE" & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & retail!=1 & wholesale!=1 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & fyear!=2008 & fyear!=2009 & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & fyear!=iddr_year & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss) keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss fyear) keepsingletons

esttab using AppxTabC4_AddRobust.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/****************AppxTabC5 -- GoodmanBacon************************/
/**********************************************************************/
clear *
use FM_NotCohortSample.dta,clear

gen id=1 if idd==0 & l_idd==1
bysort gv:egen sumid=sum(id)
drop if sumid==1
keep if fyear>=1993 & $SampSelect
keep divy_t idd $control gv fyear idd_year

xtbalance, range(1993 2019)
ddtiming divy_t idd,i(gv) t(fyear)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/****************AppxTabC6 -- CorOption************************/
/**********************************************************************/
clear *
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe tnum_options iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

eststo: quietly reghdfe tval_options iddr $control if $SampSelect & (treat==1 | control4==1) & tval_options>=0, absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1) & tnum_options==0, absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

eststo: quietly reghdfe net_repurchase iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) cluster(ss)  keepsingletons

esttab using AppxTabC6_CorOption.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/****************AppxTabC7 -- PayoutMargin************************/
/**********************************************************************/
clear *
use FM_CohortSample.dta,clear

estimates clear
eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1), absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

eststo: quietly reghdfe divy_t iddr $control if $SampSelect & (treat==1 | control4==1) & extmar==1, absorb(gv##cohort fyear##cohort) keepsingletons cluster(ss)

esttab using AppxTabC7_PayoutMargin.csv, $repoption drop(_cons)

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/


















